/**
 * 用户未登录判断工具类
 *
 * @author JINMO
 * @since 2022/06/30 22:35
 */

package com.cskaoyan.util;

import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.exception.UnLoginException;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;

public class CheckUserLoginUtils {
    public static MarketUser checkUserLogin()  {
        Subject subject = SecurityUtils.getSubject();
        PrincipalCollection principals = subject.getPrincipals();
        if (principals == null) {
            throw new UnLoginException("未登录");
        }
        MarketUser currentUser = (MarketUser) principals.getPrimaryPrincipal();
        return currentUser;
    }
}
